/******************************************************************************
* file  : console.c
* creat : apleilx
* data  : 2021/01/20
*******************************************************************************/
#include "os_obj.h"
#include "sys_task.h"
#include "pincfg.h"
#include "com_obj.h"
#include "dataproc.h"
#include "common.h"
#include "simp_txt_analysis.h"
#include "iohandle.h"
#include "str_ext.h"

extern const txt_cmd_cfg_type cmd_list[];

static uint8_t console_buff[1024];
void cmd_analysis(uint8_t *cmd);
void sys_ui_tst(void);

/*****************************************************************************
* @brief   console task.
* @param   argument
* @return  none
*****************************************************************************/
void task_console(ULONG thread_input)
{
    uint16_t len;

	
	
    while (1)
    {
        osDelay(ms_ticks(20));

        len = com.obj01.fun->cycle_rcv_line(console_buff,1024);

        if (len > 0)
        {
            str_to_upper(console_buff);
            str_remove_l20_ascii(console_buff);

            cmd_analysis(console_buff);
        }
    }
}

/*****************************************************************************
* @brief   cmd analysis.
* @param   cmd: cmd string
* @return  none
*****************************************************************************/
void cmd_analysis(uint8_t *cmd)
{
    int index;
    
    if (txt_cmd_analysis(cmd_list, (void *)cmd, 100))
    {
      
    }
    else
    {
        if(cmd[0] == '-')
        {
            sys_st.ui.del_req = 1;
            sys_ui_tst();
        }
        if(cmd[0] == '+')
        {
            index=1;
            while(cmd[index])
            {
                sys_st.ui.ch_add = cmd[index];
                sys_ui_tst();
                index++;
            }
        }
        if(cmd[0] == 'R')
        {
            sys_st.ui.rst_comp = 0;
            sys_ui_tst();
        }
        
        
        
        dbg_print("cmd = ( %s ) --> | ", cmd);
        dbg_print("buff=%s, index=%d, remain =%d, num = %d\n", sys_st.ui.buff,sys_st.ui.obj.index_next, sys_st.ui.obj.len_remain, sys_st.ui.obj.num);
    }
}


